package com.xiaode.controller.app.user;

import com.jfinal.aop.Clear;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.interceptor.AppLoginInterceptor;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;
import javax.validation.constraints.Size;

@Path("/user")
@Api("用户相关")
@EnableCORS()
public class UserController extends Controller {
    @Inject
    UserService service;

    @ApiOper("用户登陆")
    @Clear(AppLoginInterceptor.class)
    public void login(
    		@ApiPara(value = "account", notes = "账号") String account,
    		@ApiPara(value = "password", notes = "密码") String password,
            @ApiPara(value = "code", notes = "基座编码") String code,
            @ApiPara(value = "platform", notes = "平台(1app，2welink，3web，4微信)") Integer platform)throws Exception {
        Ret ret = service.login(account, password, code, platform);
        renderJson(ret);
    }
    
    @ApiOper("绑定WElink")
    @Clear(AppLoginInterceptor.class)
    public void binDingWeLink(
    		@Size @ApiPara(value = "account",notes = "账号")String account,
    		@Size @ApiPara(value = "password",notes = "密码")String password,
    		@Size @ApiPara(value = "banDingCode",notes = "绑定码")String banDingCode)throws Exception{
        Ret ret = service.binDing(account, password, banDingCode);
        renderJson(ret);
    }

    @ApiOper("获取聊天token")
    public void getWsToken() throws Exception {
    	Integer accountId = getAttr("accountId");
    	Ret ret = service.getWsToken(accountId);
    	renderJson(ret);
    }

    @ApiOper("修改密码")
    public void modifyPassword(@Size @ApiPara(value = "newPassword",notes = "新密码")String newPassword)throws Exception{
    	Integer accountId = getAttr("accountId");
        Ret ret = service.modifyPassword(accountId, newPassword);
        renderJson(ret);
    }
    
    @ApiOper("头像上传")
    public void importHead(@Size @ApiPara(value = "head",notes = "头像")String head)throws Exception{
    	Integer accountId = getAttr("accountId");
    	Integer userType = getAttr("userType");
        Ret ret = service.importHead(accountId, userType, head);
        renderJson(ret);
    }
    
	@ApiOper("获取个人基本信息")
	public void getMeInfo() throws Exception{
		Integer accountId = getAttr("accountId");
    	Integer userType = getAttr("userType");
		Ret ret = service.getMeInfo(accountId, userType);
    	renderJson(ret);
    }

    
    /**
     * 查询全校基本信息（id,sex,avatarUrl,number,name,clasId,accountId,userType）
     */
    @ApiOper("查询全校基本信息")
    public void findUserInfo(@ApiPara(value = "accountId",notes = "账号id")Integer accountId)throws Exception{
        Ret ret = service.findUserInfo(accountId);
        renderJson(ret);
    }
    
    @ApiOper("查询用户信息（例如：点击头像或名字的时候跳转的详情页）")
    public void findUserDetails(@Size @ApiPara(value = "accountId",notes = "账号id")Integer accountId)throws Exception{
        Ret ret = service.findUserDetails(accountId);
        renderJson(ret);
    }
    
    /**
	 * 学生获取家长绑定二维码
	 */
	public void getParentBinDingCode()throws Exception{
		Integer userType = getAttr("userType");
		Integer userId = getAttr("userId");
		Ret ret = service.getParentBinDingCode(userId, userType);
        renderJson(ret);
	}
	
	
	
	
	
}
